#include "deviceattributingsetdlg.h"
#include "ui_deviceattributingsetdlg.h"

DeviceAttributingSetDlg::DeviceAttributingSetDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DeviceAttributingSetDlg)
{
    ui->setupUi(this);
    
    connect(ui->namelineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateOKBtn()));
    connect(ui->PAlineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateOKBtn()));
    connect(ui->describelineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateOKBtn()));
    
    connect(ui->cancelBtn, SIGNAL(clicked(bool)), this, SLOT(close()));
    connect(ui->OKBtn, SIGNAL(clicked(bool)), this, SLOT(getAttributeData()));
    connect(ui->OKBtn, SIGNAL(clicked(bool)), this, SLOT(accept()));
}

DeviceAttributingSetDlg::~DeviceAttributingSetDlg()
{
    delete ui;
}

void DeviceAttributingSetDlg::updateOKBtn()
{
    QRegExp exp("^[0-9]+\\.[0-9]+\\.[0-9]+$");  //注意QString里面'\'要用'\\'表示，实际上正则'\.'就代表了'.'
    if(!ui->namelineEdit->text().isEmpty() || ui->PAlineEdit->text().contains(exp) || !ui->describelineEdit->text().isEmpty())
        ui->OKBtn->setEnabled(true);
    
    if(!ui->PAlineEdit->text().contains(exp) && ui->namelineEdit->text().isEmpty() && ui->describelineEdit->text().isEmpty())
        ui->OKBtn->setEnabled(false);
}

void DeviceAttributingSetDlg::getAttributeData()
{
    name = ui->namelineEdit->text();
    PA = ui->PAlineEdit->text();
    describe = ui->describelineEdit->text();
}
